﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace game_source_manager.utilities
{
    class file
    {
        //public attributes
        public enum FileType
        {
            None,
            Mesh,
            Gim,
            Gis,
            Ags,
            Mtg,
            Tga,
            Bmp
        }

        public FileType file_type
        {
            set
            {
                _file_type = value;
            }
            get
            {
                return _file_type;
            }
        }
        public string file_name
        {
            set
            {
                if (File.Exists(value))
                {
                    _file = new FileInfo(value);
                    _file_name = value;
                    is_exist = true;
                    _file_size = _file.Length/1024.0f;//convert to kb
                }
                else
                {
                    Console.WriteLine("{0} is not exist!!", value);
                }
            }
            get
            {
                return _file_name;
            }
        }
        public float file_size
        {
            get
            {
                return _file_size;
            }
        }
        public Boolean is_exist = false;

        //public method
        //constructor
        public file(string fileName)
        {
            file_name = fileName;
            if (is_exist)
            {
                _get_file_Type(file_name);
                if (_file_type != FileType.None)
                {
                 //   Console.WriteLine("{0} type is {1}!", file_name, file_type);
                }
                else
                    Console.WriteLine("{0} type cant be allowed!", file_name);
            }
        }

        //private attributes
        private FileType _file_type = FileType.None;
        private FileInfo _file;
        private string _file_name;
        private float _file_size;
        //private method
        private void _get_file_Type(string file_name)
        {
            string file_extention = file_name.Substring(file_name.LastIndexOf(".") + 1);
            switch (file_extention)
            {
                case "mesh" :
                    file_type = FileType.Mesh;
                    break;
                case "gim" :
                    file_type = FileType.Gim;
                    break;
                case "gis" :
                    file_type = FileType.Gis;
                    break;
                case "ags" :
                    file_type = FileType.Ags;
                    break;
                case "mtg" :
                    file_type = FileType.Mtg;
                    break;
                case "tga" :
                    file_type = FileType.Tga;
                    break;
                case "bmp" :
                    file_type = FileType.Bmp;
                    break;
                default:
                    file_type = FileType.None;
                    break;
            }
        }
    }
}
